package org.hq.mysecurity.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * 配置 redis
 */
@Configuration
public class RedisCongfig {
    @Bean
    public RedisTemplate<String, Object>  getRedisTemplate() {
        //实例化 redis
        RedisTemplate<String, Object> redis = new RedisTemplate<>();
       //设置 redis key 字符串
        redis.setKeySerializer(RedisSerializer.string());
        //设置 redis hash key 字符串
        redis.setHashKeySerializer(RedisSerializer.string());
        //设置 redis Value 为 json 数据
        redis.setValueSerializer(RedisSerializer.json());
        //设置 redis hash Value 为 json 数据
        redis.setHashValueSerializer(RedisSerializer.json());
        return redis;
    }
}
